﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Spi;

namespace netCoreStudy.Quartz
{
	public class QuartJobFactory : IJobFactory
	{
		private readonly IServiceProvider _serviceProvider;

		public QuartJobFactory(IServiceProvider serviceProvider)
		{
			_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
		}

		public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
		{
			return _serviceProvider.GetRequiredService(bundle.JobDetail.JobType) as IJob;
		}

		public void ReturnJob(IJob job)
		{
		}
	}
}

